import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  base: '/', // 确保生产环境使用正确的根路径
  server: {
    port: 5173,
    proxy: {
      '/api': {
        // target: 'http://localhost:8765',
        target: 'http://47.109.100.29:8765',
        changeOrigin: true,
      },
      '/uploads': {
        // target: 'http://localhost:8765',
        target: 'http://47.109.100.29:8765',
        changeOrigin: true,
      }
    }
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    sourcemap: false, // 生产环境不生成 sourcemap
    minify: 'esbuild', // 使用 esbuild 进行压缩，更快且无需额外依赖
    // 暂时禁用 manualChunks 避免循环依赖问题
    // rollupOptions: {
    //   output: {
    //     manualChunks: undefined
    //   }
    // }
  }
})
